package dhome.watcher;

import ate.*;

/**
 * 处理netlink socket传上来的内核消息
 * @author ravi huang
 *
 */
public final class NetlinkMessageProcessor extends AbstractWatcher implements INLMessageProcessor{
	public static final int RTM_NEWLINK=16;
	public static final int RTM_DELLINK=17;
	public static final int RTM_NEWADDR=20;                    
	public static final int RTM_DELADDR=21;
	public static final int RTM_NEWROUTE=24;
	public static final int RTM_DELROUTE=25;
	private UnixNetlinkSocket nlsocket;
	private static NetlinkMessageProcessor instance;
	
	private NetlinkMessageProcessor(){}
	
	public NetlinkMessageProcessor getInstance(){
		if(instance==null)
			instance=new NetlinkMessageProcessor();
		return instance;
	}
	public void start_watcher(){
		nlsocket = new UnixNetlinkSocket(this);
	}
	
	public void stop_watcher(){
		nlsocket.close();
	}
	
	@Override
	public void processor(byte[] arg) {		
		for(int i=0;i<arg.length;i++){
			switch(arg[i]){
				case RTM_NEWLINK:
					i++;
					this.fire_event(WatcherEvent.NEWLINK, arg[i]);
					break;
				case RTM_DELLINK:
					break;
				case RTM_NEWADDR:
					break;
				case RTM_DELADDR:
					break;
				case RTM_NEWROUTE:
					break;
				case RTM_DELROUTE:
					break;
				default:
					break;			
			}
		}
	}
}
